package com.demo;

import com.tydic.utils.LogUtil;
import org.junit.Test;

public class T_03_RunableDemo {

    @Test
    public void test() {
        Runnable runnable = new Runnable() {
            private int count = 5;

            @Override
            public void run() {
                count--;
                LogUtil.info("由" + Thread.currentThread().getName() + "计算，count = " + count);
            }
        };

        Thread thread = new Thread(runnable);
        Thread thread2 = new Thread(runnable);
        Thread thread3 = new Thread(runnable);
        Thread thread4 = new Thread(runnable);
        Thread thread5 = new Thread(runnable);

        thread.start();
        thread2.start();
        thread3.start();
        thread4.start();
        thread5.start();

        try {
            thread.join();
            thread2.join();
            thread3.join();
            thread4.join();
            thread5.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        LogUtil.info("运行结束！");
    }

}
